<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="false">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row :gutter="48">
          <a-col :span="24">
            <a-form-model-item label="业务分类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="serviceType">
              <business-category-select
                :disabled="formDisabled"
                v-model="model.serviceType"
                @back="businessCategoryHandle"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="业务名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="serviceName">
              <a-input disabled v-model="model.serviceName" placeholder="请输入业务名称"></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>


import BusinessCategorySelect from '@views/erp/components/BusinessCategorySelect';

export default {
  name: 'ErpOmcTenderServiceForm',
  components: {
    BusinessCategorySelect
  },
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    return {
      model: {},
      labelCol: {},
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 24 },
      },
      confirmLoading: false,
      validatorRules: {
        serviceType: [
          { required: true, message: '请选择业务分类!' },
        ],
      },
      url: {
        add: '/api/erp/omc/tender/erpOmcTenderService/add',
        edit: '/api/erp/omc/tender/erpOmcTenderService/edit',
        queryById: '/api/erp/omc/tender/erpOmcTenderService/queryById'
      }
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    },
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model));
  },
  methods: {
    businessCategoryHandle(obj) {
      if (obj) {
        this.model.serviceName = obj.categoryName
      }
    },
    add() {
      this.edit(this.modelDefault);
    },
    edit(record) {
      this.$refs['form'].clearValidate();
      Object.assign(this.$data, this.$options.data())
      // this.$refs.form.resetFields();
      this.model = Object.assign({}, record);
      this.visible = true;
    },
    submitForm() {
      const that = this;
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          if (!this.model.id) {
            this.model.id = parseInt(Math.random() * 1000000000000);
          }
          that.$emit('ok', this.model);
        }

      })
    },
  }
}
</script>
